//
//  DashedLineView.m
//  Nectar
//
//  Created by famer on 2023/11/10.
//  Copyright © 2023 asance. All rights reserved.
//

#import "DashedLineView.h"

@implementation DashedLineView

- (void)drawRect:(CGRect)rect {
    [super drawRect:rect];

    // 创建虚线的路径
    UIBezierPath *path = [UIBezierPath bezierPath];
    [path moveToPoint:CGPointMake(rect.origin.x, rect.size.height / 2)];
    [path addLineToPoint:CGPointMake(rect.size.width, rect.size.height / 2)];

    // 创建虚线的Layer
    CAShapeLayer *shapeLayer = [CAShapeLayer layer];
    [shapeLayer setFillColor:[[UIColor clearColor] CGColor]];
    [shapeLayer setStrokeColor:[[UIColor whiteColor] CGColor]];
    [shapeLayer setLineWidth:1.0f];
    [shapeLayer setLineJoin:kCALineJoinRound];
    [shapeLayer setLineDashPattern:[NSArray arrayWithObjects:[NSNumber numberWithInt:5],[NSNumber numberWithInt:5], nil]];
    [shapeLayer setPath:path.CGPath];

    // 将虚线Layer添加到视图的Layer中
    [self.layer addSublayer:shapeLayer];
}


@end
